package com.fantabest.common.server;

import java.util.List;

import javax.jdo.Transaction;

import com.fantabest.common.PMF;
import com.fantabest.common.client.SeasonService;
import com.fantabest.common.entity.Season;
import com.fantabest.common.server.dao.SeasonDao;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class SeasonServiceImpl extends RemoteServiceServlet implements
SeasonService  {

	public List<Season> findAll() {
		return SeasonDao.getInstance().findAll();
	}

	public Season save(Season season) {
		return SeasonDao.getInstance().save(season);
	}

	public void saveAll(List<Season> list) {
		Transaction tx = PMF.get().getPersistenceManager().currentTransaction();
		try {
			tx.begin();
			SeasonDao.getInstance().deleteAll();
			SeasonDao.getInstance().saveAll(list);
			tx.commit();
		} catch (Exception e) {
			tx.rollback();
		}
	}

}
